package com.zjuee.web.ledger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjuee.base.constant.DictionaryConstants;
import com.zjuee.base.dto.common.login.LoginDto;
import com.zjuee.base.exception.ServiceException;
import com.zjuee.base.model.common.ledger.LedgerDisposeApproval;
import com.zjuee.base.model.common.ledger.LedgerDisposeGather;
import com.zjuee.service.LedgerDisposeApprovalService;
import com.zjuee.web.ledger.mapper.LedgerDisposeApprovalMapper;
import com.zjuee.web.ledger.mapper.LedgerDisposeBillMapper;
import com.zjuee.web.ledger.mapper.LedgerDisposeGatherMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author wu liang
 * @since 1.0
 */
@Slf4j
@Service
public class LedgerDisposeApprovalServiceImpl implements LedgerDisposeApprovalService {

    @Resource
    private LedgerDisposeGatherMapper ledgerDisposeGatherMapper;
    @Resource
    private LedgerDisposeBillMapper ledgerDisposeBillMapper;
    @Resource
    private LedgerDisposeApprovalMapper ledgerDisposeApprovalMapper;
    @Resource
    LoginDto loginDto;

    @Override
    @Transactional
    public Long add(LedgerDisposeApproval type) {
        Long wldgId = type.getWldgId();
        //查询台账汇总信息
        LedgerDisposeGather ledgerDisposeGather = ledgerDisposeGatherMapper.selectById(wldgId);
        if (ledgerDisposeGather == null) {
            throw new ServiceException("台账信息不能为空!");
        }
        //台账变更信息插入
        type.setWldaAuditStatus(DictionaryConstants.WL_AUDIT_STATUS_UNAUDIT);
        type.setWldaCreateTime(new Date());
        type.setWldaCreator(loginDto.getUserName());
        ledgerDisposeApprovalMapper.insert(type);

        // 更新台账汇总信息
        ledgerDisposeGather.setWldgCanEdit(DictionaryConstants.WL_EDIT_STATUS_ING);
        ledgerDisposeGather.setWldgModifiedTime(new Date());
        ledgerDisposeGather.setWldgModifier(loginDto.getUserName());
        ledgerDisposeGatherMapper.updateById(ledgerDisposeGather);
        return 1l;
    }

    @Override
    public boolean delete(Long id, Long validateId) {
        return false;
    }

    @Override
    public boolean update(LedgerDisposeApproval type) {
        return false;
    }

    @Override
    public LedgerDisposeApproval selectById(Long id, Long validateId) {
        return null;
    }

    @Override
    public Page<LedgerDisposeApproval> list(LedgerDisposeApproval dto) {
        return null;
    }

    @Override
    public LambdaQueryWrapper<LedgerDisposeApproval> fuzzyQuery(LedgerDisposeApproval dto) {
        return null;
    }
}
